package com.minivision.sdktestdemo.theme.ui;

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.LayerDrawable;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ProgressBar;

import com.minivision.sdktestdemo.theme.utils.CustomThemeInterface;
import com.minivision.sdktestdemo.theme.utils.ThemeUtils;
import com.minivision.sdktestdemo.theme.utils.ViewAttributeUtils;

/**
 * Created by Administrator on 2016/6/21.
 */
public class CustomThemeProgressBar extends ProgressBar implements CustomThemeInterface {
    public CustomThemeProgressBar(Context context) {
        super(context);
    }

    public CustomThemeProgressBar(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomThemeProgressBar(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public View getView() {
        return this;
    }

    @Override
    public void setTheme(Resources.Theme themeId) {
        LayerDrawable drawable = (LayerDrawable) getProgressDrawable();
        if (ViewAttributeUtils.isNeedChangeColor(this)) {
            drawable.getDrawable(1).setColorFilter(ThemeUtils.getThemeColor(), PorterDuff.Mode.SRC_ATOP);
        } else {
            drawable.getDrawable(1).setColorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP);
        }
    }
}
